package Frames;

import Classes.Cliente;
import Classes.GeradoRelatorios;
import Classes_Conexao.ClienteDAO;
import java.awt.Dimension;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;





import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JRException;

public class CadastroCliente extends javax.swing.JInternalFrame {

    Cliente cliente = new Cliente();
    private DefaultTableModel modelo = null;

    public CadastroCliente() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        buttonGroup1 = new javax.swing.ButtonGroup();
        jComboBox1 = new javax.swing.JComboBox();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        btnLocalizar = new javax.swing.JButton();
        btnIncluir = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnGravar = new javax.swing.JButton();
        btnFechar = new javax.swing.JButton();
        btnNaoGravar = new javax.swing.JButton();
        btnImprimir = new javax.swing.JButton();
        CadastroCliente = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        boxCliente = new javax.swing.JCheckBox();
        boxFornecedor = new javax.swing.JCheckBox();
        txtRazaoSocial = new javax.swing.JTextField();
        txtNomeFantasia = new javax.swing.JTextField();
        boxAtivo = new javax.swing.JCheckBox();
        txtEndeco = new javax.swing.JTextField();
        mApelido = new javax.swing.JLabel();
        mNome = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        mCPF = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        mInscricao = new javax.swing.JLabel();
        txtInscricaoEstadual = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAObs = new javax.swing.JTextArea();
        jLabel16 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtBairro = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        radioFisica = new javax.swing.JRadioButton();
        radioJuridica = new javax.swing.JRadioButton();
        txtCidade = new javax.swing.JTextField();
        txtCnpj = new javax.swing.JFormattedTextField();
        txtFone = new javax.swing.JFormattedTextField();
        txtFone2 = new javax.swing.JFormattedTextField();
        txtFax = new javax.swing.JFormattedTextField();
        txtCelular = new javax.swing.JFormattedTextField();
        txtCep = new javax.swing.JFormattedTextField();
        txtUf = new javax.swing.JFormattedTextField();
        Localizar = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txtPesquisa = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jFormattedTextField1.setText("jFormattedTextField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro Cliente e Fornecedor");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        btnLocalizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Search-icon.png"))); // NOI18N
        btnLocalizar.setText("Localizar");
        btnLocalizar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnLocalizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnLocalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLocalizarActionPerformed(evt);
            }
        });

        btnIncluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/New-icon.png"))); // NOI18N
        btnIncluir.setText("Incluir");
        btnIncluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnIncluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnIncluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirActionPerformed(evt);
            }
        });

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Delete-icon.png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        btnGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Save-icon.png"))); // NOI18N
        btnGravar.setText("Gravar");
        btnGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGravarActionPerformed(evt);
            }
        });

        btnFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Log-Out-icon.png"))); // NOI18N
        btnFechar.setText("Fechar");
        btnFechar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFechar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFecharActionPerformed(evt);
            }
        });

        btnNaoGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Remove-icon.png"))); // NOI18N
        btnNaoGravar.setText("Não Gravar");
        btnNaoGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNaoGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNaoGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNaoGravarActionPerformed(evt);
            }
        });

        btnImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Print-icon.png"))); // NOI18N
        btnImprimir.setText("Imprimir");
        btnImprimir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnImprimir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirActionPerformed(evt);
            }
        });

        CadastroCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Cadastro"));

        jLabel6.setText("Fone 2");

        jLabel5.setText("Fone");

        jLabel4.setText("CEP");

        boxCliente.setSelected(true);
        boxCliente.setText("Cliente");
        boxCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                boxClienteMouseClicked(evt);
            }
        });
        boxCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxClienteActionPerformed(evt);
            }
        });

        boxFornecedor.setText("Fornecedor");
        boxFornecedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                boxFornecedorMouseClicked(evt);
            }
        });
        boxFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxFornecedorActionPerformed(evt);
            }
        });

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTable1, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.nome}"), txtRazaoSocial, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtRazaoSocial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtRazaoSocialKeyTyped(evt);
            }
        });

        txtNomeFantasia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNomeFantasiaActionPerformed(evt);
            }
        });
        txtNomeFantasia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNomeFantasiaKeyTyped(evt);
            }
        });

        boxAtivo.setSelected(true);
        boxAtivo.setText("Ativo");
        boxAtivo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                boxAtivoMouseClicked(evt);
            }
        });
        boxAtivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxAtivoActionPerformed(evt);
            }
        });

        txtEndeco.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtEndecoKeyTyped(evt);
            }
        });

        mApelido.setText("Nome Fantasia");

        mNome.setText("Razão Social");

        jLabel1.setText("Código");

        mCPF.setText("CNPJ");

        jLabel13.setText("Celular");

        jLabel8.setText("Fax");

        mInscricao.setText("Inscrição Estadual");

        txtInscricaoEstadual.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtInscricaoEstadualKeyTyped(evt);
            }
        });

        txtAObs.setColumns(20);
        txtAObs.setRows(5);
        txtAObs.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtAObsKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(txtAObs);

        jLabel16.setText("OBS.");

        jLabel7.setText("Endereço");

        txtBairro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBairroActionPerformed(evt);
            }
        });
        txtBairro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtBairroKeyTyped(evt);
            }
        });

        jLabel9.setText("Bairro");

        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });

        jLabel11.setText("Cidade");

        jLabel12.setText("UF");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo Pessoa"));

        buttonGroup1.add(radioFisica);
        radioFisica.setText("Física");
        radioFisica.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioFisicaMouseClicked(evt);
            }
        });
        radioFisica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioFisicaActionPerformed(evt);
            }
        });

        buttonGroup1.add(radioJuridica);
        radioJuridica.setSelected(true);
        radioJuridica.setText("Jurídica");
        radioJuridica.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioJuridicaMouseClicked(evt);
            }
        });
        radioJuridica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioJuridicaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(radioFisica)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radioJuridica)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(radioFisica)
                .addComponent(radioJuridica))
        );

        txtCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCidadeActionPerformed(evt);
            }
        });
        txtCidade.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCidadeKeyTyped(evt);
            }
        });

        try {
            txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtCnpj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCnpjActionPerformed(evt);
            }
        });
        txtCnpj.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCnpjFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCnpjFocusLost(evt);
            }
        });
        txtCnpj.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCnpjKeyTyped(evt);
            }
        });

        try {
            txtFone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtFone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFoneActionPerformed(evt);
            }
        });
        txtFone.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtFoneFocusGained(evt);
            }
        });
        txtFone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFoneKeyTyped(evt);
            }
        });

        try {
            txtFone2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtFone2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFone2ActionPerformed(evt);
            }
        });
        txtFone2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtFone2FocusGained(evt);
            }
        });
        txtFone2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFone2KeyTyped(evt);
            }
        });

        try {
            txtFax.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtFax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFaxActionPerformed(evt);
            }
        });
        txtFax.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtFaxFocusGained(evt);
            }
        });
        txtFax.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFaxKeyTyped(evt);
            }
        });

        try {
            txtCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtCelular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCelularActionPerformed(evt);
            }
        });
        txtCelular.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCelularFocusGained(evt);
            }
        });
        txtCelular.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCelularKeyTyped(evt);
            }
        });

        try {
            txtCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtCep.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCepKeyTyped(evt);
            }
        });

        try {
            txtUf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("UU")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtUf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtUfKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout CadastroClienteLayout = new javax.swing.GroupLayout(CadastroCliente);
        CadastroCliente.setLayout(CadastroClienteLayout);
        CadastroClienteLayout.setHorizontalGroup(
            CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CadastroClienteLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(38, 38, 38)
                        .addComponent(boxCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(boxFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(boxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(mNome, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(141, 141, 141)
                        .addComponent(mApelido, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(txtRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addComponent(txtNomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(92, 92, 92)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(txtEndeco, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(txtCep, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(61, 61, 61)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(mInscricao, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(txtUf, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(txtInscricaoEstadual, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(46, 46, 46)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addComponent(mCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addComponent(txtFone, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(txtFone2, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(txtFax, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addComponent(txtCnpj, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 592, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        CadastroClienteLayout.setVerticalGroup(
            CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CadastroClienteLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1)
                        .addGap(6, 6, 6)
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(boxCliente))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(boxFornecedor))
                    .addGroup(CadastroClienteLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(boxAtivo))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(mNome)
                    .addComponent(mApelido))
                .addGap(6, 6, 6)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9)
                    .addComponent(jLabel4))
                .addGap(6, 6, 6)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEndeco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(mInscricao))
                .addGap(6, 6, 6)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtInscricaoEstadual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jLabel13)
                    .addComponent(mCPF))
                .addGap(6, 6, 6)
                .addGroup(CadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFone2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addComponent(jLabel16)
                .addGap(6, 6, 6)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel1.getAccessibleContext().setAccessibleName(null);

        Localizar.setBorder(javax.swing.BorderFactory.createTitledBorder("Localizar"));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Pesquisa"));

        txtPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisaKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(txtPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jScrollPane2MouseClicked(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jTable1MouseEntered(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTable1MousePressed(evt);
            }
        });
        jScrollPane3.setViewportView(jTable1);

        jScrollPane2.setViewportView(jScrollPane3);

        javax.swing.GroupLayout LocalizarLayout = new javax.swing.GroupLayout(Localizar);
        Localizar.setLayout(LocalizarLayout);
        LocalizarLayout.setHorizontalGroup(
            LocalizarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LocalizarLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
                .addGap(39, 39, 39))
            .addGroup(LocalizarLayout.createSequentialGroup()
                .addGap(160, 160, 160)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(175, Short.MAX_VALUE))
        );
        LocalizarLayout.setVerticalGroup(
            LocalizarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LocalizarLayout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(139, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CadastroCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE)
                    .addComponent(Localizar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnIncluir)
                        .addGap(9, 9, 9)
                        .addComponent(btnLocalizar)
                        .addGap(9, 9, 9)
                        .addComponent(btnExcluir)
                        .addGap(9, 9, 9)
                        .addComponent(btnGravar)
                        .addGap(9, 9, 9)
                        .addComponent(btnNaoGravar)
                        .addGap(13, 13, 13)
                        .addComponent(btnImprimir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnExcluir, btnFechar, btnGravar, btnImprimir, btnIncluir, btnLocalizar, btnNaoGravar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnIncluir)
                    .addComponent(btnLocalizar)
                    .addComponent(btnExcluir)
                    .addComponent(btnGravar)
                    .addComponent(btnNaoGravar)
                    .addComponent(btnImprimir)
                    .addComponent(btnFechar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Localizar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnLocalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLocalizarActionPerformed
        if (btnLocalizar.getText().equals("Localizar")) {
            btnLocalizar.setText("Voltar");
            CadastroCliente.setVisible(false);
            Localizar.setVisible(true);
            btnIncluir.setEnabled(false);
            try {
                ClienteDAO clienteDao = new ClienteDAO();
                ArrayList<Cliente> cliente = clienteDao.retornaTodosClientes();

                modelo.setNumRows(0);

                for (Cliente c : cliente) {
                    modelo.addRow(new String[]{Integer.toString(c.getCodigo()), c.getNome(), c.getApelido(), c.getCliente(), c.getFornecedor(), c.getAtivo(), c.getTipoPessoa(), c.getEndereco(), c.getBairro(), c.getCidade(), c.getCep(), c.getUf(), c.getCgf(), c.getFone1(), c.getFone2(), c.getFax(), c.getCelular(), c.getCnpj(), c.getObs()});
                }

            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        } else {
            btnLocalizar.setText("Localizar");
            CadastroCliente.setVisible(true);
            Localizar.setVisible(false);
            btnIncluir.setEnabled(true);
        }
        btnExcluir.setEnabled(false);
        btnGravar.setText("Gravar");

    }//GEN-LAST:event_btnLocalizarActionPerformed

    private void btnIncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirActionPerformed
        if (btnLocalizar.getText().equals("Voltar")) {
            btnLocalizar.setText("Localizar");
            CadastroCliente.setVisible(true);
            Localizar.setVisible(false);
        } else {
            btnLocalizar.setText("Localizar");
            CadastroCliente.setVisible(true);
            Localizar.setVisible(false);
        }

        txtCodigo.setText("");
        txtRazaoSocial.setText("");
        txtNomeFantasia.setText("");
        txtEndeco.setText("");
        txtBairro.setText("");
        txtCep.setText("");
        txtCidade.setText("");
        txtUf.setText("");
        txtFone.setText("");
        txtFone2.setText("");
        txtFax.setText("");
        txtCelular.setText("");
        txtCnpj.setText("");
        txtInscricaoEstadual.setText("");
        txtAObs.setText("");
        radioFisica.setSelected(false);
        radioJuridica.setSelected(false);
        boxAtivo.setSelected(true);
        boxCliente.setSelected(true);
        boxFornecedor.setSelected(false);


        //desativar e ativar
        btnIncluir.setEnabled(false);
        btnLocalizar.setEnabled(false);
        btnExcluir.setEnabled(false);
        btnGravar.setEnabled(true);
        btnNaoGravar.setEnabled(true);
        btnFechar.setEnabled(false);


        //ativar e desativar campos
        txtAObs.setEnabled(true);
        txtBairro.setEnabled(true);
        txtCelular.setEnabled(true);
        txtCep.setEnabled(true);
        txtCidade.setEnabled(true);
        txtCnpj.setEnabled(true);
        txtCodigo.setEnabled(true);
        txtEndeco.setEnabled(true);
        txtFax.setEnabled(true);
        txtFone.setEnabled(true);
        txtFone2.setEnabled(true);
        txtInscricaoEstadual.setEnabled(true);
        txtNomeFantasia.setEnabled(true);
        txtRazaoSocial.setEnabled(true);
        txtUf.setEnabled(true);
        radioFisica.setEnabled(true);
        radioJuridica.setEnabled(true);
        boxAtivo.setEnabled(true);
        boxCliente.setEnabled(true);
        boxFornecedor.setEnabled(true);
        //mudar nomes dos botões
        btnGravar.setText("Gravar");
        //busca do codigo no banco
        try {
            ClienteDAO clienteDao = new ClienteDAO();
            ArrayList<Cliente> cliente = clienteDao.retornaCodigo();

            for (Cliente c : cliente) {
                txtCodigo.setText(Integer.toString(c.getCodigo() + 1));
            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnIncluirActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        UIManager.put("OptionPane.yesButtonText", "Sim");
        UIManager.put("OptionPane.noButtonText", "Não");
        UIManager.put("OptionPane.cancelButtonText", "Cancelar");
        int resultado = JOptionPane.showConfirmDialog(null, "Você deseja excluir o registro?", "Excluir", 1, 1);
        int resultado2 = JOptionPane.showConfirmDialog(null, "Tem certeza?", "Excluir", 1, 1);
        if (resultado == 0 && resultado2 == 0) {
            int linhaSelecionada = jTable1.getSelectedRow();
            Cliente cliente = new Cliente();

            cliente.setNome(jTable1.getValueAt(linhaSelecionada, 1).toString());

            try {
                ClienteDAO clienteDao = new ClienteDAO();
                clienteDao.excluir(cliente);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            modelo.removeRow(linhaSelecionada);
            // ativar e desativar os campos de texto
            txtCodigo.setText("");
            txtRazaoSocial.setText("");
            txtNomeFantasia.setText("");
            txtEndeco.setText("");
            txtBairro.setText("");
            txtCep.setText("");
            txtCidade.setText("");
            txtUf.setText("");
            txtFone.setText("");
            txtFax.setText("");
            txtFone2.setText("");
            txtCelular.setText("");
            txtCnpj.setText("");
            txtInscricaoEstadual.setText("");
            txtAObs.setText("");
            radioFisica.setSelected(false);
            radioJuridica.setSelected(false);
            boxAtivo.setSelected(true);
            boxCliente.setSelected(true);
            boxFornecedor.setSelected(false);
            //ativar e desativar campos
            txtAObs.setEnabled(false);
            txtBairro.setEnabled(false);
            txtCelular.setEnabled(false);
            txtCep.setEnabled(false);
            txtCidade.setEnabled(false);
            txtCnpj.setEnabled(false);
            txtCodigo.setEnabled(false);
            txtEndeco.setEnabled(false);
            txtFax.setEnabled(false);
            txtFone.setEnabled(false);
            txtFone2.setEnabled(false);
            txtInscricaoEstadual.setEnabled(false);
            txtNomeFantasia.setEnabled(false);
            txtRazaoSocial.setEnabled(false);
            txtUf.setEnabled(false);
            radioFisica.setEnabled(false);
            radioJuridica.setEnabled(false);
            boxAtivo.setEnabled(false);
            boxCliente.setEnabled(false);
            boxFornecedor.setEnabled(false);
            // desativar o botao excluir
            btnExcluir.setEnabled(false);
            JOptionPane.showMessageDialog(null, "Registro excluido com sucesso!");
        } else {
            return;
        }

    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGravarActionPerformed
        if (btnGravar.getText() == "Atualizar") {
            //alterar
            int linhaSelecionada = jTable1.getSelectedRow();
            Cliente cliente = new Cliente();

            cliente.setCodigo(Integer.parseInt(jTable1.getValueAt(linhaSelecionada, 0).toString())); //"Aqui é para modificação do id (Não pode ser alterado.)"
            cliente.setNome(txtRazaoSocial.getText());
            cliente.setApelido(txtNomeFantasia.getText());
            cliente.setCliente(Boolean.toString(boxCliente.isSelected()));
            cliente.setFornecedor(Boolean.toString(boxFornecedor.isSelected()));
            cliente.setAtivo(Boolean.toString(boxAtivo.isSelected()));
            cliente.setTipoPessoa(jTable1.getValueAt(linhaSelecionada, 6).toString());
            cliente.setEndereco(txtEndeco.getText());
            cliente.setBairro(txtBairro.getText());
            cliente.setCidade(txtCidade.getText());
            cliente.setCep(txtCep.getText());
            cliente.setUf(txtUf.getText());
            cliente.setFone1(txtFone.getText());
            cliente.setFone2(txtFone2.getText());
            cliente.setFax(txtFax.getText());
            cliente.setCelular(txtCelular.getText());
            cliente.setCnpj(txtCnpj.getText());
            cliente.setCgf(txtInscricaoEstadual.getText());
            cliente.setObs(txtAObs.getText());

            try {
                ClienteDAO cDao = new ClienteDAO();
                cDao.editar(cliente);

            } catch (Exception e) {
                e.printStackTrace();
            }
            btnGravar.setEnabled(false);
        } else {
            //adiciona
            if (txtRazaoSocial.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo Nome/Rasão social não pode ficar em branco");
                txtRazaoSocial.requestFocus();
                return;
            }


            if (txtEndeco.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo Endereço não pode ficar em branco");
                txtEndeco.requestFocus();
                return;
            }

            if (txtBairro.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo Bairro não pode ficar em branco");
                txtBairro.requestFocus();
                return;
            }

            if (txtCep.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo CEP não pode ficar em branco");
                txtCep.requestFocus();
                return;
            }

            if (txtCidade.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo Cidade não pode ficar em branco");
                txtCidade.requestFocus();
                return;
            }

            if (txtUf.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo UF não pode ficar em branco");
                txtUf.requestFocus();
                return;
            }

            if (txtInscricaoEstadual.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo Inscrição Estadual / RG não pode ficar em branco");
                txtInscricaoEstadual.requestFocus();
                return;
            }

            if (txtFone.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo Fone não pode ficar em branco");
                txtFone.requestFocus();
                return;
            }

            if (txtCnpj.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "O campo CNPJ / CPF não pode ficar em branco");
                txtCnpj.requestFocus();
                return;
            }

            try {
                ClienteDAO cDao = new ClienteDAO();
                Cliente c = new Cliente();
                c.setCnpj(txtCnpj.getText());

                ArrayList<Cliente> lista = cDao.buscaCPF(c);

                if (lista.size() > 0) {
                    JOptionPane.showMessageDialog(null, "Já Existe um Registro com Esse CPF / CNPJ!");
                    return;
                } else {
                    cliente.setCnpj(txtCnpj.getText());
                }
            } catch (SQLException sqle) {
                sqle.printStackTrace();
            }

            if (radioFisica.isSelected() == true) {
                cliente.setTipoPessoa("F");
            } else {
                cliente.setTipoPessoa("J");
            }

            cliente.setNome(txtRazaoSocial.getText());
            cliente.setApelido(txtNomeFantasia.getText());
            cliente.setEndereco(txtEndeco.getText());
            cliente.setBairro(txtBairro.getText());
            cliente.setCidade(txtCidade.getText());
            cliente.setCep(txtCep.getText());
            cliente.setUf(txtUf.getText());
            cliente.setFone1(txtFone.getText());
            cliente.setFone2(txtFax.getText());
            cliente.setFone2(txtFax.getText());
            cliente.setFax(txtFax.getText());
            cliente.setCelular(txtCelular.getText());
            cliente.setCgf(txtInscricaoEstadual.getText());
            cliente.setObs(txtAObs.getText());
            cliente.setFornecedor(Boolean.toString(boxFornecedor.isSelected()));
            cliente.setCliente(Boolean.toString(boxCliente.isSelected()));
            cliente.setAtivo(Boolean.toString(boxAtivo.isSelected()));


            ClienteDAO dao = null;

            try {
                dao = new ClienteDAO();
                // se caso ocorrer um erro ele vai entrar no catch
                txtRazaoSocial.getText();
                txtNomeFantasia.getText();
                txtEndeco.getText();
                txtBairro.getText();
                txtCep.getText();
                txtCidade.getText();
                txtUf.getText();
                txtFone.getText();
                txtFax.getText();
                txtFax.getText();
                txtCelular.getText();
                txtCnpj.getText();
                txtInscricaoEstadual.getText();
                txtAObs.getText();
                boxFornecedor.isSelected();
                boxCliente.isSelected();
                boxAtivo.isSelected();
                cliente.getTipoPessoa();

            } catch (SQLException ex) {
                Logger.getLogger(CadastroCliente.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                dao.adiciona(cliente);
                // se caso ocorrer um erro ele vai entrar no catch
                txtRazaoSocial.getText();
                txtNomeFantasia.getText();
                txtEndeco.getText();
                txtBairro.getText();
                txtCep.getText();
                txtCidade.getText();
                txtUf.getText();
                txtFone.getText();
                txtFax.getText();
                txtFax.getText();
                txtCelular.getText();
                txtCnpj.getText();
                txtInscricaoEstadual.getText();
                txtAObs.getText();
                boxFornecedor.isSelected();
                boxCliente.isSelected();
                boxAtivo.isSelected();
                cliente.getTipoPessoa();
            } catch (SQLException ex) {
                Logger.getLogger(CadastroCliente.class.getName()).log(Level.SEVERE, null, ex);
            }
            //fim adiciona
            //ativo e não ativo

            radioFisica.setSelected(false);
            radioJuridica.setSelected(false);
            btnNaoGravar.setEnabled(false);
            btnGravar.setEnabled(false);
            btnIncluir.setEnabled(true);
            btnLocalizar.setEnabled(true);
            btnImprimir.setEnabled(true);
            btnFechar.setEnabled(true);
        }
    }//GEN-LAST:event_btnGravarActionPerformed

    private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnFecharActionPerformed

    private void btnNaoGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNaoGravarActionPerformed
        txtCodigo.setText("");
        txtRazaoSocial.setText("");
        txtNomeFantasia.setText("");
        txtEndeco.setText("");
        txtBairro.setText("");
        txtCep.setText("");
        txtCidade.setText("");
        txtUf.setText("");
        txtFone.setText("");
        txtFax.setText("");
        txtFax.setText("");
        txtCelular.setText("");
        txtCnpj.setText("");
        txtInscricaoEstadual.setText("");
        txtAObs.setText("");
        radioFisica.setSelected(false);
        radioJuridica.setSelected(false);
        boxAtivo.setSelected(false);
        boxCliente.setSelected(false);
        boxFornecedor.setSelected(false);
        btnNaoGravar.setEnabled(false);
        btnGravar.setEnabled(false);
        btnIncluir.setEnabled(true);
        btnLocalizar.setEnabled(true);
        btnImprimir.setEnabled(true);
        btnFechar.setEnabled(true);
        //ativar e desativar campos
        txtAObs.setEnabled(false);
        txtBairro.setEnabled(false);
        txtCelular.setEnabled(false);
        txtCep.setEnabled(false);
        txtCidade.setEnabled(false);
        txtCnpj.setEnabled(false);
        txtCodigo.setEnabled(false);
        txtEndeco.setEnabled(false);
        txtFax.setEnabled(false);
        txtFone.setEnabled(false);
        txtFone2.setEnabled(false);
        txtInscricaoEstadual.setEnabled(false);
        txtNomeFantasia.setEnabled(false);
        txtRazaoSocial.setEnabled(false);
        txtUf.setEnabled(false);
        radioFisica.setEnabled(false);
        radioJuridica.setEnabled(false);
        boxAtivo.setEnabled(false);
        boxCliente.setEnabled(false);
        boxFornecedor.setEnabled(false);
    }//GEN-LAST:event_btnNaoGravarActionPerformed
    private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
        GeradoRelatorios rep = new GeradoRelatorios();
        JasperPrint relat;
        try {
            relat = rep.gerarRelatoriosClientes();
            JasperViewer.viewReport(relat, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    //}
////para chama o relatorio funcionario no botão jmenuitem por um codigo
//    private void menuitemFuncionariosActionPerformed(java.awt.event.ActionEvent evt) {
//        GeradoRelatorios rep = new GeradoRelatorios();
//        JasperPrint relat;
//        try {
//            int codigo = Integer.parseInt(JOptionPane.showInputDialog("informe o codigo"));
//            relat = rep.gerarRelatoriosFuncionarios2(codigo);
//            JasperViewer.viewReport(relat, false);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }//GEN-LAST:event_btnImprimirActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
    }//GEN-LAST:event_formWindowActivated

    private void txtCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCidadeActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtCidadeActionPerformed

    private void radioFisicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioFisicaActionPerformed
        if (radioFisica.isSelected() == true) {

            try {
                txtCnpj.setValue(null);
                txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));

            } catch (java.text.ParseException ex) {
                ex.printStackTrace();
            }


        } else {

            try {
                txtCnpj.setValue(null);
                txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));

            } catch (java.text.ParseException ex) {
                ex.printStackTrace();
            }
        }

        mNome.setText("Nome");
        mApelido.setText("Apelido");
        mCPF.setText("CPF");
        mInscricao.setText("RG");
}//GEN-LAST:event_radioFisicaActionPerformed

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtCodigoActionPerformed

    private void txtBairroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBairroActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtBairroActionPerformed

    private void txtNomeFantasiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNomeFantasiaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtNomeFantasiaActionPerformed

    private void boxFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxFornecedorActionPerformed
        btnGravar.setEnabled(true);
}//GEN-LAST:event_boxFornecedorActionPerformed

    private void txtPesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaKeyReleased
        modelo.setNumRows(0);

        try {
            ClienteDAO cDao = new ClienteDAO();
            ArrayList<Cliente> cliente = cDao.retornaClientePorNome(txtPesquisa.getText());

            for (Cliente c : cliente) {
                modelo.addRow(new String[]{Integer.toString(c.getCodigo()), c.getNome(), c.getApelido(), c.getCliente(), c.getFornecedor(), c.getAtivo(), c.getTipoPessoa(), c.getEndereco(), c.getBairro(), c.getCidade(), c.getCep(), c.getUf(), c.getCgf(), c.getFone1(), c.getFone2(), c.getFax(), c.getCelular(), c.getCnpj(), c.getObs()});

            }
        } catch (SQLException ex) {
            ex.printStackTrace();

        }
    }//GEN-LAST:event_txtPesquisaKeyReleased

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    }//GEN-LAST:event_formWindowOpened

    private void radioFisicaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioFisicaMouseClicked
    }//GEN-LAST:event_radioFisicaMouseClicked
    private void radioJuridicaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioJuridicaMouseClicked
    }//GEN-LAST:event_radioJuridicaMouseClicked
    private void txtCnpjActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCnpjActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCnpjActionPerformed

    private void txtCnpjFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCnpjFocusGained
    }//GEN-LAST:event_txtCnpjFocusGained

    private void txtFoneFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtFoneFocusGained
        try {
            txtFone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_txtFoneFocusGained

    private void txtFoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtFoneActionPerformed

    private void txtCnpjFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCnpjFocusLost
    }//GEN-LAST:event_txtCnpjFocusLost

    private void txtFone2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFone2ActionPerformed
    }//GEN-LAST:event_txtFone2ActionPerformed

    private void txtFone2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtFone2FocusGained
        try {
            txtFone2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_txtFone2FocusGained

    private void txtFaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFaxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtFaxActionPerformed

    private void txtFaxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtFaxFocusGained
        try {
            txtFax.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_txtFaxFocusGained

    private void txtCelularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCelularActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCelularActionPerformed

    private void txtCelularFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCelularFocusGained
        try {
            txtCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_txtCelularFocusGained

    private void jScrollPane2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane2MouseClicked
    }//GEN-LAST:event_jScrollPane2MouseClicked

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
    if (evt.getClickCount() == 2) {
        if (jTable1.getSelectedRow() != -1) {
            int linhaSelecionada = jTable1.getSelectedRow();
            // retorna os valores das celulas da tabela para os campos de texto!s
            txtCodigo.setText(modelo.getValueAt(linhaSelecionada, 0).toString());
            txtRazaoSocial.setText(modelo.getValueAt(linhaSelecionada, 1).toString());
            txtNomeFantasia.setText(modelo.getValueAt(linhaSelecionada, 2).toString());
            boxCliente.setSelected(Boolean.parseBoolean(modelo.getValueAt(linhaSelecionada, 3).toString()));
            boxFornecedor.setSelected(Boolean.parseBoolean(modelo.getValueAt(linhaSelecionada, 4).toString()));
            boxAtivo.setSelected(Boolean.parseBoolean(modelo.getValueAt(linhaSelecionada, 5).toString()));

            String valorRadio = modelo.getValueAt(linhaSelecionada, 6).toString();
            if (valorRadio.equals("J")) {
                radioJuridica.setSelected(true);
                if (radioJuridica.isSelected() == true) {
                    try {
                        txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
                    } catch (java.text.ParseException ex) {
                        ex.printStackTrace();
                    }
                } else {
                }
                mNome.setText("Razão Social");
                mApelido.setText("Nome Fantasia");
                mCPF.setText("CNPJ");
                mInscricao.setText("Inscrição Estadual");
                txtCnpj.setText(modelo.getValueAt(linhaSelecionada, 17).toString());
            } else {
                radioFisica.setSelected(true);
                if (radioFisica.isSelected() == true) {

                    try {
                        txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
                    } catch (java.text.ParseException ex) {
                        ex.printStackTrace();
                    }
                } else {
                }
                mNome.setText("Nome");
                mApelido.setText("Apelido");
                mCPF.setText("CPF");
                mInscricao.setText("RG");
                txtCnpj.setText(modelo.getValueAt(linhaSelecionada, 17).toString());
            }
            txtEndeco.setText(modelo.getValueAt(linhaSelecionada, 7).toString());
            txtBairro.setText(modelo.getValueAt(linhaSelecionada, 8).toString());
            txtCidade.setText(modelo.getValueAt(linhaSelecionada, 9).toString());
            txtCep.setText(modelo.getValueAt(linhaSelecionada, 10).toString());
            txtUf.setText(modelo.getValueAt(linhaSelecionada, 11).toString());
            txtInscricaoEstadual.setText(modelo.getValueAt(linhaSelecionada, 12).toString());
            txtFone.setText(modelo.getValueAt(linhaSelecionada, 13).toString());
            txtFone2.setText(modelo.getValueAt(linhaSelecionada, 14).toString());
            txtFax.setText(modelo.getValueAt(linhaSelecionada, 15).toString());
            txtCelular.setText(modelo.getValueAt(linhaSelecionada, 16).toString());
            txtAObs.setText(modelo.getValueAt(linhaSelecionada, 18).toString());

            CadastroCliente.setVisible(true);
            Localizar.setVisible(false);
            // ativar campos para edição
            txtAObs.setEnabled(true);
            txtBairro.setEnabled(true);
            txtCelular.setEnabled(true);
            txtCep.setEnabled(true);
            txtCidade.setEnabled(true);
            txtCnpj.setEnabled(true);
            txtCodigo.setEnabled(false);
            txtEndeco.setEnabled(true);
            txtFax.setEnabled(true);
            txtFone.setEnabled(true);
            txtFone2.setEnabled(true);
            txtInscricaoEstadual.setEnabled(true);
            txtNomeFantasia.setEnabled(true);
            txtRazaoSocial.setEnabled(true);
            txtUf.setEnabled(true);
            radioFisica.setEnabled(false);
            radioJuridica.setEnabled(false);
            boxAtivo.setEnabled(true);
            boxCliente.setEnabled(true);
            boxFornecedor.setEnabled(true);
            //ativar e desativar botão
            btnExcluir.setEnabled(true);
            btnIncluir.setEnabled(true);
            btnGravar.setText("Atualizar");

            if (btnLocalizar.getText().equals("Localizar")) {
                btnLocalizar.setText("Voltar");
                CadastroCliente.setVisible(false);
                Localizar.setVisible(true);
            } else {
                btnLocalizar.setText("Localizar");
                CadastroCliente.setVisible(true);
                Localizar.setVisible(false);
            }
        }
    }


}//GEN-LAST:event_jTable1MouseClicked

private void jTable1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseEntered
}//GEN-LAST:event_jTable1MouseEntered

private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed
}//GEN-LAST:event_jTable1MousePressed

private void txtRazaoSocialKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRazaoSocialKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtRazaoSocialKeyTyped

private void txtNomeFantasiaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNomeFantasiaKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtNomeFantasiaKeyTyped

private void txtEndecoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEndecoKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtEndecoKeyTyped

private void txtBairroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBairroKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtBairroKeyTyped

private void txtCepKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCepKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtCepKeyTyped

private void txtCidadeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCidadeKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtCidadeKeyTyped

private void txtUfKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtUfKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtUfKeyTyped

private void txtInscricaoEstadualKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtInscricaoEstadualKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtInscricaoEstadualKeyTyped

private void txtFoneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFoneKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtFoneKeyTyped

private void txtFone2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFone2KeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtFone2KeyTyped

private void txtFaxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFaxKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtFaxKeyTyped

private void txtCelularKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCelularKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtCelularKeyTyped

private void txtCnpjKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCnpjKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtCnpjKeyTyped

private void txtAObsKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAObsKeyTyped
    btnGravar.setEnabled(true);
}//GEN-LAST:event_txtAObsKeyTyped

private void boxClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boxClienteMouseClicked
}//GEN-LAST:event_boxClienteMouseClicked

private void boxFornecedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boxFornecedorMouseClicked
}//GEN-LAST:event_boxFornecedorMouseClicked

private void boxAtivoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boxAtivoMouseClicked
}//GEN-LAST:event_boxAtivoMouseClicked

private void radioJuridicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioJuridicaActionPerformed
    if (radioJuridica.isSelected() == true) {

        try {
            txtCnpj.setValue(null);
            txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));

        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

    } else {

        try {
            txtCnpj.setValue(null);
            txtCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));

        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
    }
    mNome.setText("Razão Social");
    mApelido.setText("Nome Fantasia");
    mCPF.setText("CNPJ");
    mInscricao.setText("Inscrição Estadual");
}//GEN-LAST:event_radioJuridicaActionPerformed

private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
    // DIMENSÕES DA TELA
    // Recupera o tamanho da tela
    java.awt.Dimension screenSize =
            java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    // Ajusta o tamanho da janela (JFrame)
    setSize(new java.awt.Dimension(700, 600));
    // Ajusta a localização da janela, dependendo do tamanho da janela em
    // relação ao tamanho da tela
    setLocation((screenSize.width - 1000) / 2, (screenSize.height - 800) / 2);
    //ativar e desativar botões
    btnIncluir.setEnabled(true);
    btnLocalizar.setEnabled(true);
    btnExcluir.setEnabled(false);
    btnGravar.setEnabled(false);
    btnNaoGravar.setEnabled(false);
    btnImprimir.setEnabled(false);
    //ativar e desativar campos
    txtAObs.setEnabled(false);
    txtBairro.setEnabled(false);
    txtCelular.setEnabled(false);
    txtCep.setEnabled(false);
    txtCidade.setEnabled(false);
    txtCnpj.setEnabled(false);
    txtCodigo.setEnabled(false);
    txtEndeco.setEnabled(false);
    txtFax.setEnabled(false);
    txtFone.setEnabled(false);
    txtFone2.setEnabled(false);
    txtInscricaoEstadual.setEnabled(false);
    txtNomeFantasia.setEnabled(false);
    txtRazaoSocial.setEnabled(false);
    txtUf.setEnabled(false);
    radioFisica.setEnabled(false);
    radioJuridica.setEnabled(false);
    boxAtivo.setEnabled(false);
    boxCliente.setEnabled(false);
    boxFornecedor.setEnabled(false);

    Localizar.setVisible(false);
    CadastroCliente.setVisible(true);





    //TABELA
    String[] colunas = new String[]{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
    String[][] dados = new String[][]{};


    modelo = new DefaultTableModel(dados, colunas) {

        public boolean isCellEditable(int row, int col) {
            return false;
        }
    };



    jTable1.setModel(modelo);
    jTable1.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Código");
    jTable1.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Nome");
    jTable1.getTableHeader().getColumnModel().getColumn(2).setHeaderValue("Apelido");
    jTable1.getTableHeader().getColumnModel().getColumn(3).setHeaderValue("Fornecedor");
    jTable1.getTableHeader().getColumnModel().getColumn(4).setHeaderValue("Cliente");
    jTable1.getTableHeader().getColumnModel().getColumn(5).setHeaderValue("Ativo");
    jTable1.getTableHeader().getColumnModel().getColumn(6).setHeaderValue("Tipo de Pessoa");
    jTable1.getTableHeader().getColumnModel().getColumn(7).setHeaderValue("Endereço");
    jTable1.getTableHeader().getColumnModel().getColumn(8).setHeaderValue("Bairro");
    jTable1.getTableHeader().getColumnModel().getColumn(9).setHeaderValue("Cidade");
    jTable1.getTableHeader().getColumnModel().getColumn(10).setHeaderValue("CEP");
    jTable1.getTableHeader().getColumnModel().getColumn(11).setHeaderValue("UF");
    jTable1.getTableHeader().getColumnModel().getColumn(12).setHeaderValue("Inscrição Estadual");
    jTable1.getTableHeader().getColumnModel().getColumn(13).setHeaderValue("Telefone 1");
    jTable1.getTableHeader().getColumnModel().getColumn(14).setHeaderValue("Telefone 2");
    jTable1.getTableHeader().getColumnModel().getColumn(15).setHeaderValue("Fax");
    jTable1.getTableHeader().getColumnModel().getColumn(16).setHeaderValue("Celular");
    jTable1.getTableHeader().getColumnModel().getColumn(17).setHeaderValue("CNPJ");
    jTable1.getTableHeader().getColumnModel().getColumn(18).setHeaderValue("OBS.");

    jTable1.getTableHeader().getColumnModel().getColumn(0).setMinWidth(40);
    jTable1.getTableHeader().getColumnModel().getColumn(1).setMinWidth(180);
    jTable1.getTableHeader().getColumnModel().getColumn(2).setMinWidth(130);
    jTable1.getTableHeader().getColumnModel().getColumn(3).setMinWidth(40);
    jTable1.getTableHeader().getColumnModel().getColumn(4).setMinWidth(40);
    jTable1.getTableHeader().getColumnModel().getColumn(5).setMinWidth(40);
    jTable1.getTableHeader().getColumnModel().getColumn(6).setMinWidth(40);
    jTable1.getTableHeader().getColumnModel().getColumn(7).setMinWidth(180);
    jTable1.getTableHeader().getColumnModel().getColumn(8).setMinWidth(130);
    jTable1.getTableHeader().getColumnModel().getColumn(9).setMinWidth(150);
    jTable1.getTableHeader().getColumnModel().getColumn(10).setMinWidth(70);
    jTable1.getTableHeader().getColumnModel().getColumn(11).setMinWidth(40);
    jTable1.getTableHeader().getColumnModel().getColumn(12).setMinWidth(110);
    jTable1.getTableHeader().getColumnModel().getColumn(13).setMinWidth(100);
    jTable1.getTableHeader().getColumnModel().getColumn(14).setMinWidth(100);
    jTable1.getTableHeader().getColumnModel().getColumn(15).setMinWidth(100);
    jTable1.getTableHeader().getColumnModel().getColumn(16).setMinWidth(100);
    jTable1.getTableHeader().getColumnModel().getColumn(17).setMinWidth(150);
    jTable1.getTableHeader().getColumnModel().getColumn(18).setMinWidth(200);

    jTable1.setPreferredScrollableViewportSize(new Dimension(2300, 0));


    try {
        ClienteDAO clienteDao = new ClienteDAO();
        ArrayList<Cliente> cliente = clienteDao.retornaTodosClientes();

        modelo.setNumRows(0);

        for (Cliente c : cliente) {
            modelo.addRow(new String[]{Integer.toString(c.getCodigo()), c.getNome(), c.getApelido(), c.getCliente(), c.getFornecedor(), c.getAtivo(), c.getTipoPessoa(), c.getEndereco(), c.getBairro(), c.getCidade(), c.getCep(), c.getUf(), c.getCgf(), c.getFone1(), c.getFone2(), c.getFax(), c.getCelular(), c.getCnpj(), c.getObs()});
        }

    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}//GEN-LAST:event_formInternalFrameOpened

private void boxAtivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxAtivoActionPerformed
    btnGravar.setEnabled(true);
}//GEN-LAST:event_boxAtivoActionPerformed

private void boxClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxClienteActionPerformed
    btnGravar.setEnabled(true);
}//GEN-LAST:event_boxClienteActionPerformed

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadastroCliente().setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel CadastroCliente;
    private javax.swing.JPanel Localizar;
    private javax.swing.JCheckBox boxAtivo;
    private javax.swing.JCheckBox boxCliente;
    private javax.swing.JCheckBox boxFornecedor;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnFechar;
    private javax.swing.JButton btnGravar;
    private javax.swing.JButton btnImprimir;
    private javax.swing.JButton btnIncluir;
    private javax.swing.JButton btnLocalizar;
    private javax.swing.JButton btnNaoGravar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel mApelido;
    private javax.swing.JLabel mCPF;
    private javax.swing.JLabel mInscricao;
    private javax.swing.JLabel mNome;
    private javax.swing.JRadioButton radioFisica;
    private javax.swing.JRadioButton radioJuridica;
    private javax.swing.JTextArea txtAObs;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JFormattedTextField txtCelular;
    private javax.swing.JFormattedTextField txtCep;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JFormattedTextField txtCnpj;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtEndeco;
    private javax.swing.JFormattedTextField txtFax;
    private javax.swing.JFormattedTextField txtFone;
    private javax.swing.JFormattedTextField txtFone2;
    private javax.swing.JTextField txtInscricaoEstadual;
    private javax.swing.JTextField txtNomeFantasia;
    private javax.swing.JTextField txtPesquisa;
    private javax.swing.JTextField txtRazaoSocial;
    private javax.swing.JFormattedTextField txtUf;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
